package merchant.space;

import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class BrowseCollectionsAdapter extends BaseExpandableListAdapter {
   
    
    private BrowseCollectionsActivity context;
    private Collections collections;
    
    public BrowseCollectionsAdapter(BrowseCollectionsActivity ccontext,Collections c)
    {	
    	
    	context=ccontext;
    	collections = c;
    	context.getExpandableListView().setChildDivider(context.getResources().getDrawable(R.color.super_blue));
    	
    }

    public Object getChild(int groupPosition, int childPosition) {
        return collections.get(groupPosition);
    }

    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    public int getChildrenCount(int groupPosition) {
    	return 1;
    }

    
    public TextView getGenericView() {
       
    	AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, 64);

        TextView textView = new TextView(context);
        textView.setLayoutParams(lp);
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
        textView.setPadding(36, 0, 0, 0);
        
        return textView;
    }


    
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, 
            View convertView, ViewGroup parentView)
    {
    	LayoutInflater inflater = context.getLayoutInflater();
        convertView = inflater.inflate(R.layout.browse_collections_child, parentView, false);
       
        
        
        ((TextView) convertView.findViewById(R.id.owner)).setText(collections.get(groupPosition).getUser());
        ((TextView) convertView.findViewById(R.id.description)).setText(collections.get(groupPosition).getDescription());
        
        Log.d("url",collections.get(groupPosition).getPhoto());
        ((ImageView) convertView.findViewById(R.id.thumbnail)).setImageBitmap(collections.get(groupPosition).getThumb());
        
        return convertView;
    }

    public Object getGroup(int groupPosition) {
        return collections.get(groupPosition);
    }

    public int getGroupCount() {
        return collections.size();
    }

    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    
    public View getGroupView(int groupPosition, boolean isExpanded, 
            View convertView, ViewGroup parentView)
    {
        
    	LayoutInflater inflater = context.getLayoutInflater();
        convertView = inflater.inflate(R.layout.browse_collections_parent, parentView, false);
        
        ((TextView) convertView.findViewById(R.id.name)).setText(collections.get(groupPosition).getName());
       
        ImageView group = (ImageView) convertView.findViewById(R.id.groupicon);
        if (collections.get(groupPosition).getVisibility()==0) group.setImageResource(R.drawable.group);
		else group.setImageResource(R.drawable.user);
        Log.d("PAREENENT",parentView.getClass().toString());
		
        return convertView;
    }

    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    public boolean hasStableIds() {
        return true;
    }
    
    

}
